package com.jobs.assertF;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;

import java.util.Map;
import java.util.Objects;

/**
 * 断言判断工具类
 */
public class AssertUtils {


    /**
     * @param condition
     * @param detail
     *            错误详细信息
     */
    public static void assertTrue(boolean condition, String detail) {
        if (!condition)
            throw new ServiceException(detail);
    }

    /**
     * @param condition
     * @param detail
     *            错误详细信息
     */
    public static void assertFalse(boolean condition, String detail) {
        if (condition)
            throw new ServiceException(detail);
    }

    /**
     * @param obj
     * @param detail
     *            错误详细信息
     */
    public static void assertNotNull(Object obj, String detail) {
        if (Objects.isNull(obj))
            throw new ServiceException(detail);
    }

    /**
     * @param str
     * @param detail
     *            错误详细信息
     */
    public static void assertNotBlank(String str, String detail) {
        if (StrUtil.isBlank(str))
            throw new ServiceException(detail);
    }

    /**
     * @param str
     * @param detail
     *            错误详细信息
     */
    public static void assertBlank(String str, String detail) {
        if (StrUtil.isNotBlank(str))
            throw new ServiceException(detail);
    }
    /**
     * @param obj
     * @param detail
     *            错误详细信息
     */
    public static void assertNull(Object obj, String detail) {
        if (Objects.nonNull(obj))
            throw new ServiceException(detail);
    }

    public static void fail(String msg) {
        throw new ServiceException(msg);
    }
}

